import java.util.Random;

import org.newdawn.slick.Color;
import org.newdawn.slick.Image;

import net.phys2d.raw.Body;


public class Platform extends Entity{

	
	public Platform(float x, float y, float width, float height, float weight) {
		super(x, y, width, height, weight);
		body.setGravityEffected(false);
		body.setRotatable(false);
		body.setMoveable(false);
		body.setFriction(0.75f);
		phaseimage = null;
		playedsound = false;
		type = Platform.getRandomType();
		initPlatform();
	}
	
	public void initPlatform() {
	if (type.equals(Type.normal)) { type = Type.normal; }
	else if (type.equals(Type.ice)) { body.setFriction(0.1f); }
	else if (type.equals(Type.mud)) { body.setFriction(4.0f); }
	else if (type.equals(Type.crumbly)) { breaks = true; phaseinit = false; phasesolid = true; phaseetimer = 500+rand.nextInt(500); }
	else if (type.equals(Type.rotates)) { rotates = true; currotation = 0.0f; rotateincrement = 180.0f; rotaterest = 0.0f; rotatespeed = 0.5f; }
	else if (type.equals(Type.slides)) { slides = true; body.setFriction(1.0f); curslide = 0.0f; slideorigin = x; slideamount = 50.0f; slideleft = true; }
	else { type = Type.normal; body.setRotatable(true); }
	}
	
	public Color getColor() {
		if (color != null) return color;
		
		else if (type.equals(Type.normal)) {
			return color = colornormal;
		}
		else if (type.equals(Type.ice)) {
			return color = colorice;
		}
		else if (type.equals(Type.mud)) {
			return color = colormud;
		}
		else if (type.equals(Type.crumbly)) {
			return color = colorcrumbly;
		}
		else if (type.equals(Type.rotates)) {
			return color = colorrotates;
		}
		else if (type.equals(Type.slides)) {
			return color = colorslides;
		}
		else
			return colornormal;
	}
	
	public static Type getRandomType() {
		Random rand = new Random();
		int r = rand.nextInt(100);
		if (r < normalchance) return Type.normal;
		else if (r < icechance) return Type.ice;
		else if (r < mudchance) return Type.mud;
		else if (r < crumblychance) return Type.crumbly;
		else if (r < rotatechance) return Type.rotates;
		else if (r < slidechance) return Type.slides;
		
		return Type.normal;
		
	}
	
	public static enum Type {normal, ice, mud, crumbly, rotates, slides};
	public static Color colornormal = Color.white;
	public static Color colorice = Color.cyan;
	public static Color colormud = Color.orange;
	public static Color colorcrumbly = Color.pink;
	public static Color colorrotates = Color.green;
	public static Color colorslides = Color.yellow;
	private static Random rand = new Random();
	
	public Type type;
	
	public boolean breaks;
	public boolean rotates;
	public boolean slides;
	public boolean slideleft;
	public boolean phaseinit;
	public boolean phasesolid;
	public boolean playedsound;
	
	public float currotation;
	public float rotateincrement;
	public float rotaterest;
	public float rotatespeed;
	
	public float slideorigin;
	public float slideamount;
	public float curslide;
	
	public float phaseetimer;
	
	public Image phaseimage;
	
	public static float normalchance = 40;
	public static float icechance = 55;
	public static float mudchance = 70;
	public static float crumblychance = 80;
	public static float rotatechance = 90;
	public static float slidechance = 100;
	
}
